<template>
  <el-form :inline="true" @submit.native.prevent>
    <el-form-item>
      <el-select v-model="queryParam.status" clearable
                 placeholder="使用状态" @change="handleQuery">
        <el-option v-for="item in Dic.isShow()"
                   :key="item.value"
                   :label="item.text"
                   :value="item.value"/>
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-input v-model="queryParam.keyword"
                @keyup.enter="handleQuery"
                placeholder="请输入名称"
                type="text"
                prefix-icon="search"
                auto-complete="off"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleQuery">搜索</el-button>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="openRow">新增</el-button>
    </el-form-item>
  </el-form>
  <el-table :data="tableData.list" v-loading="loading" border height="calc(100vh - 210px)">
    <el-table-column label="分类ID" prop="pfId" width="150" align="center"/>
    <el-table-column label="分类名称" prop="pfName" min-width="120" align="center"/>
    <el-table-column label="分类排序" prop="pfPx" width="140" align="center"/>
    <el-table-column label="是否显示" prop="pfType" width="140" align="center" :formatter="Dic.isShow"/>
    <el-table-column label="是否统计" prop="pfSftj" width="140" align="center" :formatter="Dic.isUse"/>
    <el-table-column label="操作" width="80" align="center" fixed="right">
      <template v-slot="{row}">
        <el-button link type="success" @click="openRow(row)">
          编辑
        </el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination layout="->,total,sizes,prev,pager,next,jumper"
                 v-model:current-page="queryParam.page"
                 v-model:page-size="queryParam.limit"
                 :total="tableData.total" background
                 @current-change="loadList"
                 @size-change="loadList"/>
  <category-list-detail v-model="openRowDialog"
                        :info="currentRow"
                        :refresh="loadList"
                        :close="()=>{this.openRowDialog = false}"/>
</template>

<script lang="ts">
import partsApi from "@/api/parts";
import categoryListDetail from "@/components/parts/categoryListDetail.vue";
import Dic from "@/utils/dic"

export default {
  name: "categoryList",
  components: {categoryListDetail},
  data() {
    return {
      Dic,
      queryParam: {
        page: 1,
        limit: 20,
        keyword: "",
        byLan: true,
        status: 1
      },
      tableData: {
        list: [],
        total: 0,
      },
      openRowDialog: false,
      currentRow: {},
      loading: false,
    };
  },
  created() {
    this.loadList();
  },
  methods: {
    handleQuery() {
      this.queryParam.page = 1;
      this.loadList();
    },
    loadList() {
      this.loading = true
      partsApi.categoryList(this.queryParam).then(res => {
        this.loading = false
        this.tableData = res.data
      })
    },
    openRow(row) {
      this.openRowDialog = true;
      this.currentRow = row
    }
  }
}
</script>
<style lang="scss" scoped>

</style>